package com.jindy.module.additionalDeposit.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jindy.module.drawBill.service.impl.DrawBillServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.module.additionalDeposit.domain.SyAdditionalDeposit;
import com.jindy.module.additionalDeposit.service.ISyAdditionalDepositService;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 追加押金申请Controller
 * 
 * @author jindy
 * @date 2023-05-25
 */
@RestController
@RequestMapping("/module/additionalDeposit")
public class SyAdditionalDepositController extends BaseController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(SyAdditionalDepositController.class);
    @Autowired
    private ISyAdditionalDepositService syAdditionalDepositService;

    /**
     * 查询追加押金申请列表
     */
    @PreAuthorize("@ss.hasPermi('module:additionalDeposit:list')")
    @GetMapping("/list")
    public TableDataInfo list(SyAdditionalDeposit syAdditionalDeposit)
    {
        startPage();
        List<SyAdditionalDeposit> list = syAdditionalDepositService.selectSyAdditionalDepositList(syAdditionalDeposit);
        return getDataTable(list);
    }

    /**
     * 导出追加押金申请列表
     */
    @PreAuthorize("@ss.hasPermi('module:additionalDeposit:export')")
    @Log(title = "追加押金申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SyAdditionalDeposit syAdditionalDeposit)
    {
        List<SyAdditionalDeposit> list = syAdditionalDepositService.selectSyAdditionalDepositList(syAdditionalDeposit);
        ExcelUtil<SyAdditionalDeposit> util = new ExcelUtil<SyAdditionalDeposit>(SyAdditionalDeposit.class);
        util.exportExcel(response, list, "追加押金申请数据");
    }

    /**
     * 获取追加押金申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:additionalDeposit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(syAdditionalDepositService.selectSyAdditionalDepositById(id));
    }

    /**
     * 新增追加押金申请
     */
    @PreAuthorize("@ss.hasPermi('module:additionalDeposit:add')")
    @Log(title = "追加押金申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SyAdditionalDeposit syAdditionalDeposit)
    {
        try {
            return syAdditionalDepositService.insertSyAdditionalDeposit(syAdditionalDeposit);
        } catch (Exception e) {
            LOGGER.error("新增追加押金申请失败",e);
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 修改追加押金申请
     */
    @PreAuthorize("@ss.hasPermi('module:additionalDeposit:edit')")
    @Log(title = "追加押金申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SyAdditionalDeposit syAdditionalDeposit)
    {
        return toAjax(syAdditionalDepositService.updateSyAdditionalDeposit(syAdditionalDeposit));
    }

    /**
     * 删除追加押金申请
     */
    @PreAuthorize("@ss.hasPermi('module:additionalDeposit:remove')")
    @Log(title = "追加押金申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(syAdditionalDepositService.deleteSyAdditionalDepositByIds(ids));
    }
}
